﻿@using ZX.Tools
@using ZX.Model
@model MyAgreement
@{
    Sys_UserModel user = ViewBag.User;
    List<Approval_Log> listLog = ViewBag.ListLog ?? new List<Approval_Log>();
    //List<Approval_User> listAuser = ViewBag.ListAUser ?? new List<Approval_User>();
    List<Approval> listApproval = ViewBag.ListApproval ?? new List<Approval>();
}
<link href="~/Static/styles/bootstrap.min.css" rel="stylesheet" />
<link href="~/Static/js/layer/need/layer.css" rel="stylesheet" />
<link href="~/Static/js/Validform/css/style.css" rel="stylesheet" />
<link href="~/Static/js/layui/css/layui.css" rel="stylesheet" />
<script src="/Static/js/jquery/jquery-1.11.1.min.js"></script>
<script src="~/Static/js/layui/layui.js"></script>
<script src="~/Static/js/jquery/form/min.js"></script>
<script src="~/Static/js/Validform/js/Validform_v5.3.2_min.js"></script>
<script src="~/Static/js/admin.min.js"></script>
<script src="~/Static/js/layer/layer.js"></script>
<script src="~/Static/js/layer/layer.tools.js"></script>
<style>
    .panel {
        border: 2px solid #e5e5e5 !important;
    }

    .top-navbar-index {
        position: inherit;
        width: 100%;
        margin-bottom: 0;
    }

    .with-menu {
        padding: 20px;
    }
    .table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td {
        font-size: 14px;
    }
</style>
@Html.Raw(ViewBag.SysAdminMainNavbar)
<div class='with-menu'>
    <div class='panel'>
        <div class='panel-heading'><strong><i class='icon-building'></i> 合同(协议)申请单 </strong></div>
        <div class='panel-body'>
            <form action="/MyAgreement/SaveData" method="post" class="form" id="formMyAgreement">
                <input type="hidden" name="Id" value="@Model.Id" />
                <input type="hidden" name="Status" value="@Model.Status" />
                <input type="hidden" name="HtFile" value="@Model.HtFile" />
                <table class='table table-bordered' style="border: 1px solid #ddd;">
                    <tr>
                        <th class="text-left" colspan="2">经办部门：@user.DeptName</th>
                        <th class='text-left'>经办人：@user.RealName</th>
                        <th class='text-left'>电话：@user.UPhone</th>
                    </tr>
                    <tr>
                        <th class="text-left" colspan="2">填报日期：@(Model.AddTime.ToDateFormat("yyyy-MM-dd"))</th>
                        <th class='text-left' colspan="2"><span style="float:left;line-height:2.2;">合同编号：</span><input name="HtNo" class="form-control" style="width:400px;" value="@Model.HtNo" /></th>
                    </tr>
                    <tr>
                        <th class="text-center" rowspan="5">合同立项内容</th>
                        <th class="text-center">合同名称</th>
                        <td colspan="2"><input name="HtName" class="form-control" value="@Model.HtName" /></td>
                    </tr>
                    @*
                        <tr>
                            <th class="text-center">甲方</th>
                            <td colspan="2"><input name="JiaName" class="form-control" value="@Model.JiaName" /></td>
                        </tr>
                        <tr>
                            <th class="text-center">乙方</th>
                            <td colspan="2"><input name="YiName" class="form-control" value="@Model.YiName" /></td>
                        </tr>
                    *@
                    <tr>
                        <th class="text-center">当事人</th>
                        <td colspan="2">
                            <textarea cols="20" placeholder="甲方：xxx&#13;&#10;乙方：xxx" rows="5" name="Party" class="form-control">@Model.Party</textarea>
                        </td>
                        @*<td colspan="2"><input name="Party" class="form-control" placeholder="开始日期" value="@Model.Party" /></td>*@
                    </tr>
                    <tr>
                        <th class="text-center">合同金额</th>
                        <td colspan="2">
                            <input name="TotalMoney" class="form-control" value="@Model.TotalMoney" onkeypress="$.admin.keyPress(this)"
                                   onkeyup="$.admin.keyUp(this)"
                                   onblur="$.admin.keyBlur(this)" />
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center">合同附件</th>
                        <td>
                            <button type="button" class="layui-btn" id="btnUpload">选择附件</button>
                            <a href="@Model.HtFile" target="_blank" style="@(Model.HtFile.IsNullOrEmpty()?"display:none":"")" id="afj">下载附件</a>
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center">使用印章名称</th>
                        <td colspan="3">
                            <input name="YinzName" class="form-control" value="@Model.YinzName" />
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center">合同摘要</th>
                        <td colspan="3">
                            <textarea cols="20" rows="5" name="Description" class="form-control">@Model.Description</textarea>
                        </td>
                    </tr>
                    @if (listLog.Count > 0)
                    {
                        <tr>
                            <th class="text-center w-120px">审批日志</th>
                            <td colspan="3">
                                <table>
                                    @foreach (var item in listLog)
                                    {
                                        <tr>
                                            <td style="border:0;">@(item.LContent + "，" + item.CreateTime.ToDateFormat("yyyy-MM-dd HH:mm:ss"))</td>
                                        </tr>
                                    }
                                </table>
                            </td>
                        </tr>
                    }
                    <tr>
                        <th>请选择审批流程<span style="color:red">*</span></th>
                        <td colspan='9'>
                            <select class="form-control" style="max-width:80%;" name="FK_ApprovalId" datatype="*" nullmsg="请选择审批流程">
                                <option value="">==请选择==</option>
                                @foreach (var item in listApproval)
                                {
                                    <option value="@item.Id" @(Model.FK_ApprovalId == item.Id ? "selected" : "")>@item.DName</option>
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <td colspan='3'>
                            <a href='javascript:;' class='btn btn-primary' onclick='saveCaogao()'>存为草稿</a>
                            &nbsp;&nbsp;
                            <a href='javascript:;' class='btn btn-primary' onclick='saveData()'>提交</a>
                            &nbsp;&nbsp;
                            <a href='javascript:;' class='btn btn-back' onclick='goBack()'>返回</a>
                            <span id="spmsg"></span>
                        </td>
                    </tr>
                </table>
                <input type="hidden" id="submitMsg" value="" />
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#formMyAgreement").Validform({
            tiptype: function (msg, o, cssctl) {
                var objtip = $("#spmsg");
                cssctl(objtip, o.type);
                objtip.text(msg);
            },
            callback: function (form) {
                if ($("input[name='Status']").val() == "@ApplyStatus.草稿.ToInt()") {
                    win.showLoading("正在保存...");
                    $("#formMyAgreement").ajaxSubmit(function (data) {
                        if (data.Code == 300) {
                            win.alert(data.Message);
                        } else if (data.Code == 200) {
                            win.success($("#submitMsg").val(), function () {
                                goBack();
                            }, 1000);
                        }
                    });
                } else {
                    win.confirm("确认提交审批？", function () {
                        win.showLoading("正在保存...");
                        $("#formMyAgreement").ajaxSubmit(function (data) {
                            if (data.Code == 300) {
                                win.alert(data.Message);
                            } else if (data.Code == 200) {
                                win.success($("#submitMsg").val(), function () {
                                    goBack();
                                }, 1000);
                            }
                        });
                    });
                }
                return false;
            }
        });
        layui.use('upload', function () {
            var upload = layui.upload;
            var uploadInst1 = upload.render({
                elem: '#btnUpload'
                , url: '/upload/UploadFile'
                , accept: "file"
                , before: function (obj) {
                    obj.preview(function (index, file, result) {
                        $('#afj').show().html(file.name)
                    });
                }
                , done: function (res) {
                    $("input[name='HtFile']").val(res.Data);
                }
                , error: function (res) {
                    win.alert(JSON.stringify(res));
                }
            });
        });
    });
    function saveCaogao() {
        $("input[name='Status']").val("@(ApplyStatus.草稿.ToInt())");
        $("#submitMsg").val("保存草稿成功");
        $("#formMyAgreement").submit();
    }
    function saveData() {
        if(@Model.Id==0)$("input[name='Status']").val("@(ApplyStatus.新申请.ToInt())");
        $("#submitMsg").val("提交审批成功");
        $("#formMyAgreement").submit();
    }
    function goBack() {
        window.history.go(-1);
    }
    function getDateDiff() {
        if ($("#StartTime").val() != "" && $("#EndTime").val() != "") {
            var btime = $("#StartTime").val();
            var etime = $("#EndTime").val();
            var dd = $.admin.getDateDiff(btime, etime, "dd") + 1;
            $("input[name='BLength']").val(dd);
            $("#iday").html("共 " + dd + " 天");
        }
    }
</script>
